package com.pig4cloud.pig.admin.task;

import com.pig4cloud.pig.admin.api.entity.NewsList;
import com.pig4cloud.pig.admin.constant.CommonConstant;
import com.pig4cloud.pig.admin.task.base.BaseTask;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

@Component
public class ProgramCSDNNews extends BaseTask {

	@Override
	//@Scheduled(cron = "0 0/1 * * * ?")
	public void doTask() {
		String request = httpUtilService.getRequest(1,this.getClass(),"https://blog.csdn.net/?spm=1001.2100.3001.4477", CommonConstant.UTF8);
		Document parse = Jsoup.parse(request);
		Elements select = parse.body().select(".Community").select(".Community-item");
		for(Element sele : select){
			String link = sele.select("a").attr("href");
			String topic = sele.select(".Community-h-tag").select("p").text();
			String desc = sele.select(".desc").text();
			NewsList commonData = new NewsList();
			//commonData.setId(idGenerator.nextId());
			commonData.setUrl(link);
			commonData.setCreateTime(CommonConstant.getDay());
			commonData.setTitle(topic);
			commonData.setSubTitle(desc);
			commonData.setCategory("CSDN");
			pushNewsToRedis(commonData);
		}
	}
}
